package com.asset.salesforce.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.asset.salesforce.domain.ChatterContribution;
import com.asset.salesforce.domain.Employee;

@Repository
public class ChatterContributionDaoImpl {
	@Autowired
	SessionFactory sessionFactory;
	
	public void addChatter (ChatterContribution chatter){
		Session session = sessionFactory.getCurrentSession();
		session.save(chatter);
	}
	public void editChatter (ChatterContribution chatter){
		Session session = sessionFactory.getCurrentSession();
		session.saveOrUpdate(chatter);
	}
	public void deleteChatter (ChatterContribution chatter){
		Session session = sessionFactory.getCurrentSession();
		session.delete(chatter);
	}
	public List<ChatterContribution> getAllChatters(){
		Session session = sessionFactory.getCurrentSession();
	return	session.createQuery("from ChatterContribution").list();
		
	}
	public ChatterContribution getChatterById(Integer id){ 
		Session session = sessionFactory.getCurrentSession();
		return (ChatterContribution) session.load(ChatterContribution.class, id);
	}
	
	public ChatterContribution getChatterByEmployee(Integer empId){ 
		Session session = sessionFactory.getCurrentSession();
		Query query =session.createQuery(" from ChatterContribution chatter where chatter.empId = :employeeId")
		.setParameter("employeeId", empId);
		
		
			return (ChatterContribution) query.list().get(0);
		
	}
	
	
}
